package com.dzsw.config;

import com.dzsw.filter.RepeatedReadingRequestFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MvcConfig {

    @Value("${config.stream-path}")
    private String streamPath;

    @Bean
    public FilterRegistrationBean<RepeatedReadingRequestFilter> repeatedReadingRequestWrapper() {
        FilterRegistrationBean<RepeatedReadingRequestFilter> regBean = new FilterRegistrationBean<>();
        RepeatedReadingRequestFilter filter = new RepeatedReadingRequestFilter(streamPath);
        regBean.setFilter(filter);
        List<String> urls = new ArrayList<>();
        urls.add("/non/multi/*");
        regBean.setUrlPatterns(urls);
        regBean.setOrder(1);
        return regBean;
    }
}
